﻿using System.Collections.Generic;
using System.Data.Linq;
using System.Data.SqlClient;
using System.Linq;

namespace Data.DataAccess.Database
{
    public class DbUserAccess
    {
        protected string str_connection_string;

        public DbUserAccess(string str_connection_string)
        {
            this.str_connection_string = str_connection_string;
        }

        public void AddUser(TFS_USER oUser)
        {
            TfsPendingCheckinDataContext oTFS = new TfsPendingCheckinDataContext(str_connection_string);

            oTFS.TFS_USERs.InsertOnSubmit(oUser);

            oTFS.SubmitChanges();
        }

        public void UpdateUser(TFS_USER oUser)
        {
            TfsPendingCheckinDataContext oTFS = new TfsPendingCheckinDataContext(str_connection_string);
            TFS_USER oUserToUpdate = oTFS.TFS_USERs.SingleOrDefault(user => user.USER_ID == oUser.USER_ID);
            oUserToUpdate.USER_EMAIL = oUser.USER_EMAIL;

            oTFS.SubmitChanges();
        }

        public TFS_USER GetUser(string str_name)
        {
            TfsPendingCheckinDataContext oTFS = new TfsPendingCheckinDataContext(str_connection_string);

            TFS_USER oUser = oTFS.TFS_USERs.SingleOrDefault(user => user.USER_LOGIN == str_name);

            return oUser;
        }
    }
}
